home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / ds3100.md / gdb / mips-xdep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-01  |  4.1 KB  |  181 lines

  1. /* Low level MIPS interface to ptrace, for GDB when running under Unix.
  2.    Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
  3.    Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
  4.    and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
  5.  
  6. This file is part of GDB.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "defs.h"
  23. #include <mips/inst.h>
  24. #include "frame.h"
  25. #include "inferior.h"
  26. #include "symtab.h"
  27. #include "value.h"
  28.  
  29. #ifdef USG
  30. #include <sys/types.h>
  31. #endif
  32.  
  33. #include <sys/param.h>
  34. #include <sys/dir.h>
  35. #include <signal.h>
  36. #include <sys/ioctl.h>
  37. /* #include <fcntl.h>  Can we live without this?  */
  38.  
  39. #include "gdbcore.h"
  40.  
  41. #include <sys/user.h>        /* After a.out.h  */
  42. #include <sys/file.h>
  43. #include <sys/stat.h>
  44.  
  45. /* For now we stub this out; sgi format is super-hairy (and completely
  46.    different in the new release) */
  47.  
  48. #ifdef sgi
  49. void
  50. fetch_core_registers ()
  51. {
  52.   return;
  53. }
  54.  
  55. /* ARGSUSED */
  56. void
  57. fetch_inferior_registers (regno)
  58.      int regno;
  59. {
  60.   return;
  61. }
  62.  
  63. /* ARGSUSED */
  64. void
  65. store_inferior_registers (regno)
  66.      int regno;
  67. {
  68.   return;
  69. }
  70.  
  71.  
  72. #else
  73.  
  74. /* Map gdb internal register number to ptrace address. */
  75.  
  76. #define REGISTER_PTRACE_ADDR(regno) \
  77.  (regno < 32 ? regno         \
  78.   : regno == PC_REGNUM ? 96    \
  79.   : regno == CAUSE_REGNUM ? 97    \
  80.   : regno == HI_REGNUM ? 98    \
  81.   : regno == LO_REGNUM ? 99    \
  82.   : regno == FCRCS_REGNUM ? 100    \
  83.   : regno == FCRIR_REGNUM ? 101    \
  84.   : regno >= FP0_REGNUM ? regno - (FP0_REGNUM-32)\
  85.   : 0)
  86.  
  87. /* Get all registers from the inferior */
  88.  
  89. void
  90. fetch_inferior_registers (regno)
  91.      int regno;
  92. {
  93.   register unsigned int regaddr;
  94.   char buf[MAX_REGISTER_RAW_SIZE];
  95.   register int i;
  96.  
  97.   registers_fetched ();
  98.  
  99.   for (regno = 1; regno < NUM_REGS; regno++)
  100.     {
  101.       regaddr = REGISTER_PTRACE_ADDR (regno);
  102.       for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
  103.      {
  104.        *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0);
  105.        regaddr += sizeof (int);
  106.      }
  107.       supply_register (regno, buf);
  108.     }
  109. }
  110.  
  111. /* Store our register values back into the inferior.
  112.    If REGNO is -1, do this for all registers.
  113.    Otherwise, REGNO specifies which register (so we can save time).  */
  114.  
  115. void
  116. store_inferior_registers (regno)
  117.      int regno;
  118.  {
  119.   register unsigned int regaddr;
  120.   char buf[80];
  121.  
  122.   if (regno == 0)
  123.     return;
  124.  
  125.   if (regno > 0)
  126.     {
  127.       regaddr = REGISTER_PTRACE_ADDR (regno);
  128.       errno = 0;
  129.       ptrace (6, inferior_pid, regaddr, read_register (regno));
  130.       if (errno != 0)
  131.     {
  132.       sprintf (buf, "writing register number %d", regno);
  133.       perror_with_name (buf);
  134.     }
  135.     }
  136.   else
  137.     {
  138.       for (regno = 0; regno < NUM_REGS; regno++)
  139.     {
  140.       if (regno == ZERO_REGNUM || regno == PS_REGNUM
  141.           || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM
  142.           || regno == FCRIR_REGNUM || regno == FP_REGNUM
  143.           || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM))
  144.         continue;
  145.       regaddr = register_addr (regno, 1);
  146.       errno = 0;
  147.       ptrace (6, inferior_pid, regaddr, read_register (regno));
  148.       if (errno != 0)
  149.         {
  150.           sprintf (buf, "writing all regs, number %d", regno);
  151.           perror_with_name (buf);
  152.         }
  153.     }
  154.     }
  155. }
  156.  
  157. #endif /* sgi */
  158.  
  159. #if 0
  160. void
  161. fetch_core_registers ()
  162. {
  163.   register int regno;
  164.   int val;
  165.  
  166.   for (regno = 1; regno < NUM_REGS; regno++) {
  167.     char buf[MAX_REGISTER_RAW_SIZE];
  168.  
  169.     val = bfd_seek (core_bfd, register_addr (regno, 0));
  170.     if (val < 0 || (val = bfd_read (core_bfd, buf, sizeof buf)) < 0) {
  171.       char buffer[50];
  172.       strcpy (buffer, "Reading register ");
  173.       strcat (buffer, reg_names[regno]);
  174.  
  175.       perror_with_name (buffer);
  176.     }
  177.     supply_register (regno, buf);
  178.   }
  179. }
  180. #endif /* 0 */
  181.